package demo;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;

import com.alibaba.fastjson.JSON;
import com.jfinal.core.Controller;

public class HelloController extends Controller{
	
	public void index(){
		renderJsp("/view/index.jsp");
	}
	
	public void getPageData() throws IOException{
		String data = getPara("data");
		String keyword = getPara("keyword");
		List<DataExcel> list =JSON.parseArray(data, DataExcel.class);
		Workbook workbook =  ExcelExportUtil.exportExcel(new ExportParams(
				keyword, null, "Sheet1"), DataExcel.class, list);
        File savefile = new File("D:/excel/");
        if (!savefile.exists()) {
            savefile.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream("D:/excel/"+keyword+".xls");
        workbook.write(fos);
        fos.close();
        renderFile(new File("D:/excel/"+keyword+".xls"));
//		renderNull();
	}
}
